package cn.sycoder.controller;

import cn.sycoder.exception.*;
import cn.sycoder.resp.Resp;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 异常处理增强控制
 */
@RestControllerAdvice
public class ExceptionHandlerController {

    // 业务异常
    @ExceptionHandler(BusinessException.class)
    public Resp handlerBusinessException(BusinessException e){
        return new Resp(e.getCode(),null,e.getMessage());
    }

    // 系统异常
    @ExceptionHandler(SystemException.class)
    public Resp handlerSystemException(SystemException e){
        return new Resp(e.getCode(),null,e.getMessage());
    }

    // 持久层异常
    @ExceptionHandler(DaoException.class)
    public Resp handlerDaoException(DaoException e){
        return new Resp(e.getCode(),null,e.getMessage());
    }

    // 拦截器异常
    @ExceptionHandler(InterceptorException.class)
    public Resp handlerInterceptorException(DaoException e){
        return new Resp(e.getCode(),null,e.getMessage());
    }

    // 其他异常
    @ExceptionHandler(OtherException.class)
    public Resp handlerOtherException(OtherException e){
        return new Resp(e.getCode(),null,e.getMessage());
    }
}
